﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QuanLyBanHang.VO
{
    public class CartItem
    {
        int _masp,_soluong,_gia;
        long tonggia;
        string _tensp;
        public int MaSP { get { return _masp; } set { _masp = value; } }
        public string TenSP { get { return _tensp; } set { _tensp = value; } }
        public int soluong { get { return _soluong; } set { _soluong = value; } }
        public int gia { get { return _gia; } set { _gia = value; } }
        public long TongGia { get { return _soluong*_gia; } set { tonggia = value; } }    
        public CartItem(int masp, string ten, int soluong, int gia)
        {
            _masp = masp; _tensp = ten; _soluong = soluong; _gia = gia;
        }               
    }
    public class HoaDon_VO
    {
        public int MaKH;
        public int MaNV;
        public int MaHD;
        List<CartItem> _items;
        public HoaDon_VO(int makh)
        {
            MaKH = makh;
            _items = new List<CartItem>();
        }
        public HoaDon_VO()
        {
            _items = new List<CartItem>();
        }
        public List<CartItem> Items
        {
            get { return _items; }
            set { _items = value; }
        }
        public bool AddCart(CartItem c)
        {
            if (c.gia > 0)
            {
                foreach (CartItem e in Items)
                {
                    if (e.MaSP == c.MaSP)
                    {
                        e.soluong += c.soluong;
                        return true;
                    }
                }
                _items.Add(c);
            }
            return true;
        }
        public void Clean()
        {
            try
            {
                foreach (CartItem e in Items)
                {
                    if (e.soluong <= 0) Items.Remove(e);
                }
            }
            catch
            {
            }
        }
        long _tonggia;
        public long TongGia
        {
            get
            {
                long tong=0;
                foreach(CartItem c in _items)
                {
                    tong += c.TongGia;
                }
                return tong;
            }
            set
            {
                _tonggia = value;
            }
        }
        

        
                

        
        
    }
}
